package com.gzhryc.shared_device.oem.code.member.dao.db;

import com.gzhryc.common.NumberTools;
import com.gzhryc.common.StringTools;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.DateBranchTable;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.jdbc.enums.DateBranchTableType;
import com.gzhryc.shared_device.base.enums.EPayState;
import com.gzhryc.shared_device.base.enums.EPayType;
import com.gzhryc.shared_device.oem.code.member.dao.enums.MemberRechargeOrderEnum;

import java.io.Serializable;
import java.util.Date;

/**
 * 会员充值订单
 * @version 2022-10-13
 */
@DateBranchTable(type = DateBranchTableType.year)
@Table(name="member_recharge_order")
public class MemberRechargeOrder implements Serializable {

    private static final long serialVersionUID = 1L;

	@Id(auto = false)
    @Column(name = "trade_no",length=32)
    protected String tradeNo;

    @Column(name = "source_type", notNull = true, defVal = "1", note = "充值来源，1:直充，2:订单")
    protected Integer sourceType;

    @Column(name = "business_trade_no", note = "业务订单号")
    protected String businessTradeNo;

    @Column(name = "member_id")
    protected Long memberId;

    @Column(name = "nickname", note = "会员昵称")
    protected String nickname;

    @Column(name = "phone", length = 16, note = "会员手机号")
    protected String phone;

    @Column(name = "money", note = "充值金额")
    protected Integer money;

    @Column(name = "pay_type", notNull = true, defVal = "1", note = "支付类型")
    protected Integer payType;

    @Column(name = "pay_trade_no", length = 32, note = "支付订单")
    protected String payTradeNo;

    @Column(name = "pay_date", note = "支付时间")
    protected Date payDate;

    @Column(name = "pay_money", notNull = true, defVal = "0", note = "支付金额，单位：分")
    protected Integer payMoney;

    @Column(name = "refund_money", notNull = true, defVal = "0", note = "退款金额，单位：分")
    protected Integer refundMoney;

    @Column(name = "pay_state", notNull = true, defVal = "1", note = "订单支付状态")
    protected Integer payState;

    @Column(notNull = true, defVal = "1", note = "订单状态")
    protected Integer state;

    @Column(name = "operate_state", notNull = true, defVal = "1", note = "操作状态，数据库锁字段")
    protected Integer operateState;

    @Column(name = "update_date", autoUpdateTime = true, note = "修改时间")
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    public String getTradeNo() {
        return tradeNo;
    }

    public void setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
    }

    public Integer getSourceType() {
        return sourceType;
    }

    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    public String getBusinessTradeNo() {
        return businessTradeNo;
    }

    public void setBusinessTradeNo(String businessTradeNo) {
        this.businessTradeNo = businessTradeNo;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public Integer getPayType() {
        return payType;
    }

    public void setPayType(Integer payType) {
        this.payType = payType;
    }

    public String getPayTradeNo() {
        return payTradeNo;
    }

    public void setPayTradeNo(String payTradeNo) {
        this.payTradeNo = payTradeNo;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Integer getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(Integer payMoney) {
        this.payMoney = payMoney;
    }

    public Integer getRefundMoney() {
        return refundMoney;
    }

    public void setRefundMoney(Integer refundMoney) {
        this.refundMoney = refundMoney;
    }

    public Integer getPayState() {
        return payState;
    }

    public void setPayState(Integer payState) {
        this.payState = payState;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Integer getOperateState() {
        return operateState;
    }

    public void setOperateState(Integer operateState) {
        this.operateState = operateState;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Integer getResidueMoney() {
        if (this.payMoney != null) {
            if (this.refundMoney != null) {
                return this.payMoney - this.refundMoney;
            } else {
                return this.payMoney;
            }
        }
        return 0;
    }

    public String getPayTypeName() {
        return EPayType.note(this.payType);
    }

    public String getMoneyStr() {
        return NumberTools.getMoneyStr(this.money);
    }

    public String getPayMoneyStr() {
        return NumberTools.getMoneyStr(this.payMoney);
    }

    public String getRefundMoneyStr() {
        return NumberTools.getMoneyStr(this.refundMoney);
    }

    public String getPayStateName() {
        return EPayState.note(this.payState);
    }

    public String getStateName() {
        return MemberRechargeOrderEnum.State.note(this.state);
    }
    
    public String getSourceTypeName() {
    	return MemberRechargeOrderEnum.SourceType.note(this.sourceType);
    }

    public String getMemberFullName() {
        if (StringTools.isNotBlank(this.phone)) {
            return this.nickname + "(" + this.phone + ")";
        } else {
            return this.nickname;
        }
    }
}
